package yu.liu.personal.app.myapplication.components.items;

import android.content.Context;
import android.graphics.Color;
import android.widget.ImageView;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import yu.liu.personal.app.myapplication.R;
import yu.liu.personal.app.myapplication.components.ViewCollection;
import yu.liu.personal.app.myapplication.models.AVGItem;

/**
 * Created by Administrator on 2016/9/25.
 */

public class AVGListGroupItem extends ViewCollection {

    @BindView(R.id.tvIDGrpItem)
    TextView tvIDGrpItem;

    @BindView(R.id.ivIconGrpItem)
    ImageView ivIconGrpItem;

    @BindView(R.id.tvNameGrpItem)
    TextView tvNameGrpItem;

    @BindView(R.id.ivTypeIconGrpItem)
    ImageView ivTypeIconGrpItem;

    @BindView(R.id.tvTypeGrpItem)
    TextView tvTypeGrpItem;

    @BindView(R.id.tvStarGrpItem)
    TextView tvStarGrpItem;

    private AVGItem item;

    public AVGListGroupItem(Context context) {
        super(context);
    }

    public void setItem(AVGItem item) {
        this.item = item;
    }

    @Override
    protected void loadViews() {
//        tvIDGrpItem = (TextView) contentView.findViewById(resManager.getResourceID
// ("id", "tvIDGrpItem"));
//        ivIconGrpItem = (ImageView) contentView.findViewById(resManager
// .getResourceID("id", "ivIconGrpItem"));
//        tvNameGrpItem = (TextView) contentView.findViewById(resManager
// .getResourceID("id", "tvNameGrpItem"));
//        ivTypeIconGrpItem = (ImageView) contentView.findViewById(resManager
// .getResourceID("id", "ivTypeIconGrpItem"));
//        tvTypeGrpItem = (TextView) contentView.findViewById(resManager
// .getResourceID("id", "tvTypeGrpItem"));
//        tvStarGrpItem = (TextView) contentView.findViewById(resManager
// .getResourceID("id", "tvStarGrpItem"));
        ButterKnife.bind(this, contentView);
    }

    @Override
    public void updateViews() {
        if(item != null) {
            tvIDGrpItem.setText(String.valueOf(item.id));
            ivIconGrpItem.setImageResource(resManager.getResourceID("drawable", "icon_"+item.id));
            tvNameGrpItem.setText(item.name);
            ivTypeIconGrpItem.setImageResource(resManager.getAVGType(item.type));
            tvTypeGrpItem.setText(item.type);
            tvStarGrpItem.setText(String.valueOf(item.stars)+"星");
            contentView.setBackgroundColor(item.selected? Color.parseColor("#FFC125")
                    :Color.parseColor("#E9F4FD"));
        }
    }
}
